home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 41.zip / BS1 part 41 / STFX-soundsystemdisk.adf / sources / ZOUNDMON.CFILES / Zound.c < prev    next >
C/C++ Source or Header  |  1988-01-20  |  2KB  |  73 lines

  1. #include <exec/types.h>
  2. #include <libraries/dos.h>
  3.  
  4. #define MEMF_CHIP (1L<<1)
  5. #define VOICES          4
  6. #define PARTLEN        32
  7. #define TABLEN        256
  8. #define NOPARTS       256
  9.  
  10. static ULONG ZMemsize[16];
  11. static UBYTE SN;
  12. static UBYTE MaxPart,MaxTable;
  13.  
  14. static WORD Periods[]=
  15. { 0x0000,0x0358,0x0328,0x02fa,0x02d0,0x02a6,0x0280,0x025c,
  16.   0x023a,0x021a,0x01fc,0x01e0,0x01c5,0x01ac,0x0194,0x017d,
  17.   0x0168,0x0153,0x0140,0x012e,0x011d,0x010d,0x00fe,0x00f0,
  18.   0x00e2,0x00d6,0x00ca,0x00be,0x00b4,0x00aa,0x00a0,0x0097,
  19.   0x008f,0x0087,0x007f,0x0078,0x0071
  20. };
  21.  
  22. static UBYTE count,partvec,tabvec,tablen=2,speed=6,StartTab,EndTab,loadstart,loadend;
  23. static struct TabData {UBYTE partno,volume,instradd,noteadd;} Table[TABLEN][VOICES];
  24. static struct SampleData {ULONG start;UBYTE name[40];UBYTE vol;UWORD length,replen,restart;UBYTE preset;}
  25.               Sample[16];
  26. static ULONG Parts[NOPARTS][PARTLEN];
  27. static WORD dmaconhulp;
  28.  
  29. #include "Player.c"
  30.  
  31. PlayZound(start,end)register UBYTE start,end;
  32. { if(start||end){StartTab=start;EndTab=end;}
  33.   else{StartTab=loadstart;EndTab=loadend;}
  34.   SetUpInterrupt();
  35. }
  36.  
  37. QuitZound()
  38. { register int i;
  39.   for(i=0;i<16;i++)if(Sample[i].start)FreeMem(Sample[i].start,ZMemsize[i]);
  40. }
  41.  
  42. static LoadSample(dir)register char *dir;
  43. { register ULONG lock,dirlock,fh,ret=FALSE;
  44.   if(!(Sample[SN].name[0]))ret=TRUE;else
  45.   { if(lock=Lock(dir,1005))
  46.     { dirlock=CurrentDir(lock);
  47.       if(ZMemsize[SN]=FileSize(Sample[SN].name))
  48.       { if(Sample[SN].start=AllocLoad(Sample[SN].name,ZMemsize[SN],MEMF_CHIP))
  49.         { ret=TRUE;*(UWORD*)(Sample[SN].start)=0;
  50.           Sample[SN].length=ZMemsize[SN]/2;
  51.         }
  52.       }UnLock(CurrentDir(dirlock));
  53.     }
  54.   }
  55.   return ret;
  56. }            
  57.  
  58. LoadZound(songname,path)register char *songname,*path;
  59. { register int i,ret=TRUE;
  60.   long fh=Open(songname,1005);
  61.   if(fh)
  62.   { Read(fh,&MaxTable,1);Read(fh,&MaxPart,1);
  63.     Read(fh,&loadstart,1);Read(fh,&loadend,1);Read(fh,&speed,1);
  64.     for(i=0;i<16;i++)Read(fh,&Sample[i],sizeof(struct SampleData));
  65.     for(i=0;i<=MaxTable;i++)Read(fh,&Table[i][0],VOICES*sizeof(struct TabData));
  66.     for(i=0;i<=MaxPart;i++)Read(fh,&Parts[i][0],4*32);
  67.     Close(fh);
  68.     for(SN=0;SN<16;SN++)ret&=LoadSample(path);
  69.     if(!ret)QuitZound();
  70.   }else ret=FALSE;
  71.   return ret;
  72. }
  73.